import requests

# https://movie.douban.com/explore

headers = {
    'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/109.0.0.0 Safari/537.36',
    'Referer': 'https://movie.douban.com/explore',
}
url = 'https://m.douban.com/rexxar/api/v2/movie/recommend?refresh=0&start=0&count=20&selected_categories=%7B%7D&uncollect=false&tags='
res = requests.get(url, headers=headers)
items = res.json()['items']

for m in items:
    if "title" in m and "pic" in m:
        title_name = m["title"]

        # 进行图片的下载
        res = requests.get(m['pic']['large'], headers=headers)
        with open(f'./img/{title_name}.jpg', 'wb') as f:
            f.write(res.content)
        print(title_name, '下载完成！')
    else:
        print("该项没有标题或图片")
